package com.example.idachuappone.index.ui;

import java.util.Timer;
import java.util.TimerTask;

import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.Gallery;

public class MyGallery extends Gallery {
	private static final int timerAnimation = 1;
	private final Handler mHandler;
	private final TimerTask task;
	private int timeLong;
	private final Timer timer;

	public MyGallery(Context paramContext) {
		super(paramContext);
		this.timeLong = 5000;
		this.mHandler = new Handler() {
			@Override
			public void handleMessage(Message msg) {
				switch (msg.what) {
				case timerAnimation /* 1 */:
					if (MyGallery.this.getSelectedItemPosition() >= MyGallery.this.getCount() - 1) {
						MyGallery.this.onKeyDown(21, null);
					} else {
						MyGallery.this.onKeyDown(22, null);
					}
				default:
				}
			}
		};
		this.timer = new Timer();
		this.task = new TimerTask() {
			@Override
			public void run() {
				MyGallery.this.mHandler.sendEmptyMessage(timerAnimation);
			}
		};
		this.timer.schedule(this.task, this.timeLong, this.timeLong);
	}

	public MyGallery(Context paramContext, AttributeSet paramAttributeSet) {
		super(paramContext, paramAttributeSet);
		this.timeLong = 5000;
		this.mHandler = new Handler() {
			@Override
			public void handleMessage(Message msg) {
				switch (msg.what) {
				case timerAnimation /* 1 */:
					if (MyGallery.this.getSelectedItemPosition() >= MyGallery.this.getCount() - 1) {
						MyGallery.this.onKeyDown(21, null);
					} else {
						MyGallery.this.onKeyDown(22, null);
					}
				default:
				}
			}
		};
		this.timer = new Timer();
		this.task = new TimerTask() {
			@Override
			public void run() {
				MyGallery.this.mHandler.sendEmptyMessage(timerAnimation);
			}
		};
		this.timer.schedule(this.task, this.timeLong, this.timeLong);
	}

	public MyGallery(Context paramContext, AttributeSet paramAttributeSet, int paramInt) {
		super(paramContext, paramAttributeSet, paramInt);
		this.timeLong = 5000;
		this.mHandler = new Handler() {
			@Override
			public void handleMessage(Message msg) {
				switch (msg.what) {
				case timerAnimation /* 1 */:
					if (MyGallery.this.getSelectedItemPosition() >= MyGallery.this.getCount() - 1) {
						MyGallery.this.onKeyDown(21, null);
					} else {
						MyGallery.this.onKeyDown(22, null);
					}
				default:
				}
			}
		};
		this.timer = new Timer();
		this.task = new TimerTask() {
			@Override
			public void run() {
				MyGallery.this.mHandler.sendEmptyMessage(timerAnimation);
			}
		};
		this.timer.schedule(this.task, this.timeLong, this.timeLong);
	}

	private boolean isScrollingLeft(MotionEvent paramMotionEvent1, MotionEvent paramMotionEvent2) {
		return paramMotionEvent2.getX() > paramMotionEvent1.getX();
	}

	@Override
	public boolean onFling(MotionEvent paramMotionEvent1, MotionEvent paramMotionEvent2, float paramFloat1,
			float paramFloat2) {
		onKeyDown(
				isScrollingLeft(paramMotionEvent1, paramMotionEvent2) ? 21 : 22,
				null);
		return true;
	}

	public void destroy() {
		this.timer.cancel();
	}
}
